<script setup name="pageSysConfig">
import { ref } from 'vue'
import { useStore } from 'vuex'
import { getSystemSettings, updateSystemSettings } from '@/apis/common'

const store = useStore()
const configData = ref({})
const formRefSysConfig = ref(null)
const formRules = {
    systemName: [{ required: true, message: '请输入标题', trigger: 'blur' }],
    pageSize: [{ required: true, message: '请输入页码', trigger: 'blur' }]
}

// 获取网站配置
const getAppConfig = (() => {
    getSystemSettings().then((res) => {
        configData.value = res
    })
})()
const updateConfig = () => {
    formRefSysConfig.value.validate((valid) => {
        if (!valid) return false
        $Common.fullLoading()
        updateSystemSettings(configData.value).then(res => {
            $Common.closeFullLoading()
            $Common.alert("操作成功!").then(() => {
                store.dispatch("setSystemConfig", JSON.parse(JSON.stringify(configData.value)))
            })
        })
    })
}
</script>

<template>
    <div class="page-sysConfig">
        <el-form :model="configData" :rules="formRules" ref="formRefSysConfig" label-width="100px" size="large">
            <el-form-item label="项目名称" prop="systemName">
                <el-input placeholder="请输入标题" v-model="configData.systemName"></el-input>
            </el-form-item>
            <el-form-item label="页码" prop="pageSize">
                <el-input placeholder="请输入页码" v-model="configData.pageSize"></el-input>
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" @click="updateConfig()">保存配置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<style scoped lang="scss">
  .page-sysConfig {
    .el-form {
      width: 60%;
      min-width: 250px;
      margin-top: 30px;
    }
  }
</style>